package com.qf.controller;

import com.qf.dto.OrderHandle;
import com.qf.entity.Orders;
import com.qf.entity.OrdersDetails;
import com.qf.service.OrderHandleService;
import com.qf.service.OrdersService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Resource
    private OrdersService ordersService;

    @Resource
    private OrderHandleService orderHandleService;

    @GetMapping("/getAllUnManageOrders")
    public List<Orders> getAllUnManageOrders(){
        System.out.println("来了");
        return ordersService.getAllUnManageOrders();
    }

    @GetMapping("/getAllUnPayOrders")
    public List<Orders> getAllUnPayOrders(){
        return ordersService.getAllUnPayOrders();
    }

    @GetMapping("/getAllFinishOrders")
    public List<Orders> getAllFinishOrders(){
        return ordersService.getAllFinishOrders();
    }

    @GetMapping("/gethandleOrders/{oid}")
    public String gethandleOrders(@PathVariable Integer oid){
        System.out.println(oid);
        try {
            ordersService.gethandleOrders(oid);
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
            return "fail";
        }
    }

    @GetMapping("/deleteOrders/{oid}")
    public String deleteOrders(@PathVariable Integer oid){
        try {
            ordersService.deleteOrders(oid);
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
            return "fail";
        }
    }

    @GetMapping("/getFinsiOrdersByOdid/{oname}")
    public List<OrderHandle> getFinsiOrdersByOdid(@PathVariable String  oname){
        System.out.println(oname);
        return orderHandleService.findAllHandleOrders(oname);
    }
}
